<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="content-type" content="no-cache, must-revalidate"/>
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT"/>
    <title>公交车路线信息详情</title>

    <link href="css/bootstrap.min.css" rel="stylesheet"/>
    <link href="css/my.css" rel="stylesheet"/>
    <link href="css/nav.css" rel="stylesheet">
    <style>
        [v-cloak] {
            display: none;
        }
    </style>

</head>
<body>
<div id="wrapper" v-cloak>
    <div class="nav-container-header">
        <div class="container" style="height: 100%">
            <div class="row" style="height: 100%">
                <div class="col-md-3"><img class="logo-img" src="/front/img/logo.png" alt="">
                    <div class="logo">公交查询系统</div>
                </div>
                <div class="col-md-7"><img class="header-img" src="/front/img/carousel/7.jpg" alt=""></div>
            </div>
        </div>
    </div>
    <div class="nav-container">
        <ul class="nav-item-box">
            <li><a class="nav-item" href="index.html">首页</a></li>
            <li><a class="nav-item" href="advertiserInfo.html">公告信息</a></li>
			<li><a class="nav-item active" href="pathInfo.html">公交车路线信息</a></li>
			<li><a class="nav-item" href="messageInfo.html">留言信息</a></li>

            <li><a class="nav-item" href="/end/page/index.html" target="_blank">进入后台系统</a></li>
        </ul>
        <div class="nav-right">
            <a class="nav-item" href="/end/page/login.html" target="_blank">登录</a>
            <a class="nav-item" href="/end/page/register.html" target="_blank">注册</a>
        </div>
    </div>
    <div class="container" style="margin-top: 10px">
        <div class="info">
            <div class="row">
                <div class="col-md-8 col-md-offset-2">
                    <div class="panel panel-default">
                        <div class="panel-body bg-gray">
							<div class="row p-10" style="margin-bottom: 10px">
								<div class="col-md-2">班次：</div>
								<div class="col-md-10">{{ obj.name }}</div>
							</div>
							<div class="row p-10" style="margin-bottom: 10px">
								<div class="col-md-2">首班车时间：</div>
								<div class="col-md-10">{{ obj.startTime }}</div>
							</div>
							<div class="row p-10" style="margin-bottom: 10px">
								<div class="col-md-2">起始站：</div>
								<div class="col-md-10">{{ obj.start }}</div>
							</div>
							<div class="row p-10" style="margin-bottom: 10px">
								<div class="col-md-2">终点站：</div>
								<div class="col-md-10">{{ obj.end }}</div>
							</div>
							<div class="row p-10" style="margin-bottom: 10px">
								<div class="col-md-2">线路：</div>
								<div class="col-md-10">{{ obj.path }}</div>
							</div>
							<div class="row p-10" style="margin-bottom: 10px">
								<div class="col-md-2">末班车时间：</div>
								<div class="col-md-10">{{ obj.endTime }}</div>
							</div>

                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- /. 表单数据 -->

        <div class="comment" v-if="isComment">
            <div class="row">
                <div class="col-md-8 col-md-offset-2">
                    <h2>评论</h2>
                </div>
            </div>


            <div class="comment-item">
                <!--                <div class="row mt-10">-->
                <!--                    <div class="col-md-8 col-md-offset-2" style="font-size: 20px; font-weight: bold">admin</div>-->
                <!--                </div>-->
                <div class="row mt-10">
                    <div class="col-md-8 col-md-offset-2" style="text-align: justify">
                        <textarea style="resize:none; width: 100%" rows="3" v-model="comment.content"></textarea>
                    </div>
                </div>
                <div class="row mt-10">
                    <div class="col-md-8 col-md-offset-2" style="text-align: right;">
                        <button class="btn btn-primary f-r" @click="add()">发送</button>
                        <hr>
                    </div>
                </div>
            </div>


            <div class="comment-item" v-for="item in comments">
                <div class="row mt-10">
                    <div class="col-md-8 col-md-offset-2" style="font-size: 20px; font-weight: bold">{{ item.name }}
                    </div>
                </div>
                <div class="row mt-10">
                    <div class="col-md-8 col-md-offset-2" style="text-align: justify">
                        {{ item.content }}
                    </div>
                </div>
                <div class="row mt-10">
                    <div class="col-md-8 col-md-offset-2" style="text-align: right;">
                        <span style="color: #888888">{{ item.time }}</span>
                        <hr>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>

<script>

    new Vue({
        el: '#wrapper',
        data: {
            imgWidth: '0px',
            comments: [],
            content: '',
            obj: {},
            isComment: false,
            comment: {
                content: '',
                foreignId: 0
            },
            fileSrc: ''
        },
        created() {
            let id = this.getQueryVariable('id');
            this.comment.foreignId = id;
            if (id !== 0) {
                axios.get('/pathInfo/' + id).then(res => {
                    if (res.data.code === '0') {
                        let obj = res.data.data;
                        this.obj = obj;
                        if (obj.fileName) {
                            if (/\.(png|jpg|gif|jpeg|webp)$/.test(obj.fileName)) {
                                this.obj.fileType = 'image';
                            } else if (/\.mp4$/.test(obj.fileName)) {
                                this.obj.fileType = 'video';
                            } else {
                                this.obj.fileType = 'other';
                            }
                            this.fileSrc = '/files/download/' + obj.fileId;

                            let img = new Image();
                            img.src = this.fileSrc;
                            let _this = this;
                            img.onload = function(){
                                if (img.width > 590) {
                                    _this.imgWidth = "100%";
                                } else {
                                    _this.imgWidth = img.width + "px";
                                }
                            };
                        }
                    } else {
                        alert(res.data.msg)
                    }
                });
                this.loadComments(id);
            }
        },
        methods: {
            add() {
                if (this.comment.content === '') {
                    return;
                }
                axios.post('/pathInfoComment', this.comment).then(res => {
                    if (res.data.code === '0') {
                        this.comment.content = '';
                        this.loadComments(this.comment.foreignId);
                    } else {
                        alert(res.data.msg);
                    }
                })
            },
            loadComments(id) {
                axios.get('/pathInfoComment/findByForeignId/' + id).then(res => {
                    if (res.data.code === '0') {
                        this.comments = res.data.data;
                    } else {
                        alert(res.data.msg)
                    }
                })
            },
            getQueryVariable(key) {
                let query = window.location.search.substring(1);
                let vars = query.split("&");
                for (let i = 0; i < vars.length; i++) {
                    let pair = vars[i].split("=");
                    if (pair[0] === key) {
                        return pair[1];
                    }
                }
                return '';
            }
        }
    })
</script>
</body>
</html>